package com.bl.weilan.service.biz.institutionteam.impl;

import com.bl.weilan.common.ApiResponseCode;
import com.bl.weilan.common.CommonServiceException;
import com.bl.weilan.common.utils.UUIDUtils;
import com.bl.weilan.dao.model.InstitutionTeamEntity;
import com.bl.weilan.dao.repository.InstitutionTeamRepository;
import com.bl.weilan.service.biz.institutionteam.InstitutionTeamService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.institutionteam.InstitutionTeamAddVo;
import com.bl.weilan.service.vo.institutionteam.InstitutionTeamModVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Log4j2
public class InstitutionTeamServiceImpl implements InstitutionTeamService {

    @Autowired
    InstitutionTeamRepository institutionTeamRepository;

    @Override
    public void add(InstitutionTeamAddVo institutionTeamAddVo) {
        InstitutionTeamEntity institutionTeamEntity = new InstitutionTeamEntity();
        institutionTeamEntity.setId(UUIDUtils.getUUID());
        BeanUtils.copyProperties(institutionTeamAddVo, institutionTeamEntity);

        institutionTeamRepository.save(institutionTeamEntity);
    }

    @Override
    public void modify(InstitutionTeamModVo institutionTeamModVo){
        InstitutionTeamEntity institutionTeamEntity = institutionTeamRepository.findOne(institutionTeamModVo.getId());

        if (institutionTeamEntity == null) {
            throw new CommonServiceException(ApiResponseCode.DATA_INCORRECT.getCode(), "没有对应信息");
        }

        BeanUtils.copyProperties(institutionTeamModVo, institutionTeamEntity);
        institutionTeamRepository.save(institutionTeamEntity);
    }

    @Override
    public void del(DelBody id) {
        institutionTeamRepository.delete(id.getId());
    }

    @Override
    public void delList(DelListBody idList) {
        for(String id : idList.getList()) {
            institutionTeamRepository.delete(id);
        }
    }

}
